import { formatExcelDate } from './formateExcel'
export function ZHTOEN(list:ExcelObject[]){
  const mapInfo = {
    '入职日期': 'timeOfEntry',
    '手机号': 'mobile',
    '姓名': 'username',
    '转正日期': 'correctionTime',
    '工号': 'workNumber',
    '部门': 'departmentName',
    '聘用形式': 'formOfEmployment',
  }
  return list.map((item) => {
    const zhKeys=Object.keys(item)
    return zhKeys.reduce((obj,zhKey) => {
      //const enKey=mapInfo[zhKey as keyof MapInfo]s
      const enKey=prop(mapInfo,zhKey as keyof MapInfo)
      const isDate= enKey==='timeOfEntry' || enKey==='correctionTime'
      if (isDate) {
        obj[enKey] = formatExcelDate(item[zhKey as keyof ExcelObject] as number).replace(/\//g, '-')
      } else {
        //const value=item[zhKey as keyof ExcelObject] 
        obj[enKey] =item[zhKey as keyof ExcelObject]
      }
      // obj[enKey as keyof ExcelData ]= isDate ? formatExcelDate(item[zhKey as keyof ExcelData] ) 
      //:item[zhKey as keyof ExcelData] 
      //obj[enKey as keyof ExcelData ]=item[zhKey as keyof ExcelData] 
      return obj
    },<ExcelData>{})
  })
}
function pluck<T, K extends keyof T>(o: T, names: K[]): T[K][] {
  return names.map(n => o[n])
}
function prop<T, K extends keyof T>(obj: T, key: K):T[K] {
  return obj[key]
}
